package com.pinusmusic.web.serlvet;

import com.pinusmusic.domain.MusicLanguage;
import com.pinusmusic.domain.MusicStyle;
import com.pinusmusic.service.SortService;
import com.pinusmusic.service.impl.SortServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import javax.sound.midi.Soundbank;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@WebServlet("/sort/*")
public class SortServlet extends BaseServlet {
    private SortService sortService = new SortServiceImpl();
    public void findAllLanguage(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<MusicLanguage> languageList = sortService.findAllLanguage();
        Collections.sort(languageList, new Comparator<MusicLanguage>() {
            @Override
            public int compare(MusicLanguage o1, MusicLanguage o2) {
                return o1.getMusiclanguageid() - o2.getMusiclanguageid();
            }
        });
        writeValue(response,languageList);
    }

    public void findAllStyle(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<MusicStyle> styleList =  sortService.findAllStyle();
        Collections.sort(styleList, new Comparator<MusicStyle>() {
            @Override
            public int compare(MusicStyle o1, MusicStyle o2) {
                return o1.getMusicstyleid() - o2.getMusicstyleid();
            }
        });
        writeValue(response,styleList);
    }
}
